package com.ruoyi.system.domain.dto;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.constant.UserConstants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * @author nanyang
 */
public class PmsArchivesDto {

    @Data
    @ApiModel("PmsArchivesDto - Insert")
    public static class Insert {
        @NotNull(message = "姓名不能为空")
        @ApiModelProperty("姓名")
        private String name;
        @ApiModelProperty("姓名全拼")
        private String pinyinFull;
        @ApiModelProperty("姓名简拼")
        private String pinyinSimple;
        @NotNull(message = "性别不能为空")
        @ApiModelProperty("性别 1 : 男 ， 0 : 女")
        private Byte sex;
        @NotNull(message = "年龄不能为空")
        @ApiModelProperty("年龄")
        private Integer age;
        @NotNull(message = "身份证不能为空")
        @ApiModelProperty("身份证")
        private String idCard;
//        @NotNull(message = "民族不能为空")
        @ApiModelProperty("民族")
        private String nation;
//        @NotNull(message = "联系电话不能为空")
        @ApiModelProperty("联系电话")
        private String phone;
        @ApiModelProperty("身高")
        private String height;
        @ApiModelProperty("体重")
        private String weight;
        @ApiModelProperty("bmi")
        private String bmi;
        @ApiModelProperty("更新标识：0第一次输入，1更新患者信息")
        private Byte status;
        @ApiModelProperty("数据来源")
        private Integer source;
        @ApiModelProperty("备注")
        private String remark;

        @NotNull(message = "档案类型不能为空")
        @ApiModelProperty("档案类型(0:筛查； 1:； 2:治疗； 3:康复)")
        private Byte type;

        @ApiModelProperty("子表数据")
        private List<ArchivesRecordDto> recordDtoList;


        public Byte getSex() {
            return (byte) IdcardUtil.getGenderByIdCard(idCard);
        }

        public Integer getAge() {
            return IdcardUtil.getAgeByIdCard(idCard);
        }

    }

    @Data
    @ApiModel("修改档案")
    public static class Update {
        @ApiModelProperty("ID")
        private Long id;
        @ApiModelProperty("姓名")
        private String name;
        @ApiModelProperty("姓名全拼")
        private String pinyinFull;
        @ApiModelProperty("姓名简拼")
        private String pinyinSimple;
        @ApiModelProperty("性别")
        private Byte sex;
        @ApiModelProperty("年龄")
        private Integer age;
        @ApiModelProperty("身份证")
        private String idCard;
        @ApiModelProperty("民族")
        private String nation;
        @ApiModelProperty("联系电话")
        private String phone;
        @ApiModelProperty("身高")
        private String height;
        @ApiModelProperty("体重")
        private String weight;
        @ApiModelProperty("bmi")
        private String bmi;
        @ApiModelProperty("更新标识：0第一次输入，1更新患者信息")
        private String status;
        @ApiModelProperty("数据来源")
        private String source;
        @ApiModelProperty("备注")
        private String remark;
        @ApiModelProperty("子表数据")
        private List<ArchivesRecordDto> recordDtoList;
        private Long fileNum;

        @NotNull(message = "档案类型不能为空")
        @ApiModelProperty("档案类型(0:筛查； 1:； 2:治疗； 3:康复)")
        private Byte type;
    }

    @Data
    @ApiModel("删除档案")
    public static class Delete {
        @ApiModelProperty("删除ID")
        private List<Long> idList;
    }


    @Data
    @ApiModel("查询档案")
    public static class Query {
        @ApiModelProperty("档案ID")
        private Long id;
        @ApiModelProperty("姓名")
        private String name;
        @ApiModelProperty("身份证")
        private String idCard;
        @ApiModelProperty("code集合")
        private List<String> codeList;
        @ApiModelProperty("子表数据")
        private List<ArchivesRecordDto> recordDtoList;
        private String zyh;

        @NotNull(message = "档案类型不能为空")
        @ApiModelProperty("档案类型(0:筛查； 1:； 2:治疗； 3:康复)")
        private Byte type;

        @ApiModelProperty("档案菜单ID")
        private Long tagId;

        @ApiModelProperty("随访状态（0：待随访，1：已随访）")
        private String flupFlag;

        private List<Long> idList;
        private  String select;

        private List<String> zdbm;
        @ApiModelProperty("诊断名称")
        private String zzmc;

//        @ApiModelProperty("手术操作标化名称")
//        private List<String> operationName;

        @ApiModelProperty("手术操作标化名称")
        private String operationName;

        @ApiModelProperty("数据来源")
        private Integer source;

        @ApiModelProperty("档案号")
        private String fileNum;

        @ApiModelProperty("所属项目")
        private String projectId;

        @ApiModelProperty("治疗类型")
        private List<String> treatmentTypes;

        @ApiModelProperty("手术方式")
        private List<String> operationWay;

        @ApiModelProperty("所属科室")
        private String departmentId;

        @ApiModelProperty("档案状态")
        private String archivesType;

//        public List<String> getZzmc() {
//            if (StrUtil.isNotEmpty(zzmc)) {
//                String[] split = zzmc.split(",");
//                return Arrays.stream(split).collect(Collectors.toList());
//            }
//            return null;
//        }

        private List<String> ssbmList;
        private String isJmrs = null;

//        public String getJmrs() {
//            isJmrs = null;
//            if (CollectionUtil.isNotEmpty(operationWay)) {
//                if (operationWay.contains("0")) {
//                    isJmrs = "1";
//                }
//            }
//            return isJmrs;
//        }

        public List<String> getTreatmentTypes() {
            List<String> list = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(treatmentTypes)) {
                if (treatmentTypes.contains("AIS静脉溶栓")) {
//                    list.addAll(UserConstants.AISJRZT);
                }
                if (treatmentTypes.contains("AIS介入再通")) {
                    list.addAll(UserConstants.AISJRZT);
                }
                if (treatmentTypes.contains("脑出血")) {
                    list.addAll(UserConstants.NCXCC);
                }
                if (treatmentTypes.contains("颅内动脉瘤")) {
                    list.addAll(UserConstants.LNDML);
                }
                if (treatmentTypes.contains("CES/CAS")) {
                    list.addAll(UserConstants.CEA);
                    list.addAll(UserConstants.CAS);
                }
            }
            return treatmentTypes;
        }


        //溶栓0 AISJMRS
        //
        //桥接1
        //
        //AIS介入再通2 AISJRZT
        //
        //开颅血肿3 NCXQC
        //
        //去骨瓣减压4
        //
        //钻孔血肿5
        //
        //复合手术6
        //
        //CEA 10 11 CEA
        //
        //CAS 12 CAS
        //桥接 39.28 颅外-颅内动脉吻合术 即颅内外动脉搭桥术
        //去骨瓣减压术 01.25 颅骨切开术 无单独编码，归类于此
        //脑室镜下血肿抽吸术 01.39 + 01.51 颅内血肿清除术 + 脑室镜 组合编码，01.39常为主码
        //钻孔血肿抽吸术 01.31 颅骨钻孔伴硬膜下血肿引流术 特指硬膜下血肿
        // 01.24 + 01.39 颅骨钻孔术 + 颅内血肿清除术 适用于硬膜外等其他血肿
        //复合手术 无单一编码  需分别对开放和介入操作进行编码
        //介入栓塞术 39.72 颅内血管栓塞术 常需与血管造影术(88.41)一起编码
        //闭夹术 39.51 动脉瘤夹闭术 特指颅内动脉瘤夹闭
        public List<String> getssbmList() {
            List<String> list = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(operationWay)) {
//                if (operationWay.contains("0")) {
//                    list.addAll(UserConstants.AISJMRS);
//                }
                if (operationWay.contains("1")) {
                    //桥接
                    list.add("39.28");
                }
                if (operationWay.contains("2")) {
                    //AIS介入再通
                    list.addAll(UserConstants.AISJRZT);
                }
                if (operationWay.contains("3")) {
                    //开颅血肿
                    list.addAll(UserConstants.NCXQC);
                }
                if (operationWay.contains("4")) {
                    //去骨瓣减压
                    list.add("01.25");
                    list.add("01.39");
                    list.add("01.51");
                }
                if (operationWay.contains("5")) {
                    //钻孔血肿
                    list.add("01.31");
                    list.add("01.24");
                    list.add("01.39");
                }
//                if (operationWay.contains("6")) {
//                    //复合手术
//                }
//                if (operationWay.contains("7")) {
//                    //其他
//                }
                if (operationWay.contains("8")) {
                    //接入栓塞术
                    list.add("39.72");
                    list.add("88.41");
                }
                if (operationWay.contains("9")) {
                    //闭夹术
                    list.add("39.51");
                }
                if (operationWay.contains("10")) {
                    list.addAll(UserConstants.CEA);
                }
                if (operationWay.contains("11")) {
                    list.addAll(UserConstants.CEA);
                }
                if (operationWay.contains("12")) {
                    list.addAll(UserConstants.CAS);
                }
            }
            return list;
        }

        public List<ArchivesRecordDto> getRecordDtoList() {
            if (CollectionUtil.isEmpty(recordDtoList)) {
                return recordDtoList;
            }
            List<ArchivesRecordDto> list = new ArrayList<>();
            for (ArchivesRecordDto archivesRecordDto : recordDtoList) {
                if (StrUtil.isNotBlank(archivesRecordDto.getCode()) && StrUtil.isNotEmpty(archivesRecordDto.getAnswer())) {
                    list.add(archivesRecordDto);
                }
            }
            return list;
        }

        public List<String> getCodeList() {
            if (CollectionUtil.isNotEmpty(codeList)) {
                codeList.remove("");
                return codeList;
            }
            return codeList;
        }
    }

    @Data
    @ApiModel("查询档案详情")
    public static class QueryDetail {
        @NotNull(message = "请选择档案")
        @ApiModelProperty("档案ID")
        private Long id;
        @ApiModelProperty("姓名")
        private String name;
        @ApiModelProperty("身份证")
        private String idCard;
        @ApiModelProperty("code集合")
        private List<String> codeList;
        @ApiModelProperty("子表数据")
        private List<ArchivesRecordDto> recordDtoList;

        @NotNull(message = "档案类型不能为空")
        @ApiModelProperty("档案类型(0:筛查； 1:； 2:治疗； 3:康复)")
        private Byte type;

        @ApiModelProperty("档案菜单ID")
        private Long tagId;

        public List<String> getCodeList() {
            if (CollectionUtil.isNotEmpty(codeList)) {
                codeList.remove("");
                return codeList;
            }
            return codeList;
        }
    }

    @Data
    @ApiModel("档案子表")
    public static class ArchivesRecordDto {
        @ApiModelProperty("key")
        private String code;
        @ApiModelProperty("value")
        private String answer;
    }

}
